const Person = require('../../../models/person'); import dbConnect from '../../../utils/helpers/dbHelpers'; async function handler(req, res) { const { method } = req; await dbConnect(); switch (method) { case 'GET': { try { const dataId = req.query.dataId; const person = await Person.findOne({ customID: dataId }); if (!person) { throw new Error('Person with this id does not exist!'); } res.status(200).json({ message: 'Fetch single data successfull!', singleData: person, }); } catch (error) { res.status(400).json({ message: error.message }); } break; } default: res.status(405).json({ message: 'Method not allowed' }); break; } } export default handler;